#ifndef _CQUE_H_
#define _CQUE_H_
#include "CSem.h"

#ifdef __cplusplus
extern "C" {
#endif

#define WRITE_LOCK      1
#define WRITE_UNLOCK    0

#define POP_OK      0
#define POP_FAILED  1
#define PUSH_OK      0
#define PUSH_FAILED  1

typedef struct _cque_ {
	//attribute
//public none

//private
    int is_lock_when_write;
	CSem lock;
    char* q_buf;
    int q_buf_size;
    int msg_cnt; //数据包有效个数
    int used_bytes;
    int r_idx; //任何时候从data[r_idx]开始读出
    int w_idx;

	//action
	int(*push)(struct _cque_*, const char*, unsigned short);
	int (*pop)(struct _cque_*, char*, unsigned short*);
    int (*set_queue_buf)(struct _cque_*, char*, int);
//	int(*release)(struct _cque_* thes);
} CQue;

void construct_queue(CQue* thes, int with_lock);

#ifdef __cplusplus
}
#endif
#endif
